<template>
  <div class="searchHistory">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span>全部删除</span>
        &nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true" />
    </van-cell>

    <van-cell
      v-for="(histores, index) in searchHistores"
      :key="index"
      :title="histores"
      @click="onDelete(histores)"
    >
      <van-icon @click="onDelete(index)" name="close" v-show="isDeleteShow"
    /></van-cell>
  </div>
</template>

<script>
import {removeItem} from '@/util/storage'
export default {
  props: {
    searchHistores: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      isDeleteShow: false, //删除的显示状态
    };
  },
  methods: {
    onDelete(histores,index) {
      if (this.isDeleteShow) {
       this.searchHistores.splice(index, 1);
       removeItem("search-histories")
       return 
      }
      //非展示状态 点击搜索结果
      this.$emit('search',histores)
    },
  },
};
</script>

<style lang="less" scoped>
</style>